package com.jcw.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.jcw.common.R;
import com.jcw.domain.Employee;
import com.jcw.service.EmployeeService;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

@Slf4j
@RestController
@RequestMapping("/employee")
public class EmployeeController {
    @Resource
    private EmployeeService employeeService;

    @PostMapping("/login")
    public R<Employee> login(@RequestBody Employee employee){
        return employeeService.login(employee);
    }

    @PostMapping("/logout")
    public R<String> logout(){
        return employeeService.logout();
    }

    @GetMapping("/page")
    public R<Page> pageR(@RequestParam int page,int pageSize,String name){
        return employeeService.pagination(page,pageSize,name);
    }

    @PostMapping
    public R<String> addEmployee(@RequestBody Employee employee){
        return employeeService.add(employee);
    }

    @GetMapping("/{id}")
    public R<Employee> get(@PathVariable Long id){
        return employeeService.getEmployee(id);
    }

    @PutMapping
    public R<String> updateEmployee(@RequestBody Employee employee){
        return employeeService.editEmployee(employee);
    }


}
